package models

import (
	"gorm.io/gorm"
	"time"
	"user_srv/basic/config"
)

type Driver struct {
	Id               uint           `gorm:"column:id;type:bigint(20) UNSIGNED;primaryKey;not null;" json:"id"`
	UserId           uint           `gorm:"column:user_id;type:bigint(20);comment:用户ID;not null;" json:"user_id"`                                                   // 用户ID
	DriverLicenseUrl string         `gorm:"column:driver_license_url;type:varchar(255);comment:驾驶证照片;not null;" json:"driver_license_url"`                       // 驾驶证照片
	LicenseNumber    uint           `gorm:"column:license_number;type:int(10);comment:驾驶证号;not null;" json:"license_number"`                                      // 驾驶证号
	CarType          string         `gorm:"column:car_type;type:varchar(50);comment:车型;not null;" json:"car_type"`                                                  // 车型
	Status           uint           `gorm:"column:status;type:tinyint(1) UNSIGNED;comment:审核状态:1:待审核，2:审核成功，3:审核失败;not null;default:1;" json:"status"` // 审核状态:1:待审核，2:审核成功，3:审核失败
	CreatedAt        time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt        time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt        gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (d *Driver) TableName() string {
	return "driver"
}
func (d *Driver) CreateDriver() error { //成为司机
	return config.DB.Create(&d).Error
}
func (d *Driver) GetDirverById() error {
	return config.DB.Where("id = ?", d.Id).Limit(1).Find(&d).Error
}
func (d *Driver) CheckDirverStatus() error {
	return config.DB.Model(&Driver{}).Where("id = ?", d.Status).Update("status", d.Status).Error
}
